<?php
namespace app\index\controller;

use think\Controller;
use think\View;
use Jssdk\JSSDK;

class WxJssdk extends CheckMember
{
    /**
     * 微信分享sdk代码
     * @return mixed
     */
    public function share()
    {
        try
        {
            $member = model('member')->get(['id' => session('member_id')]);

            $jssdk = new JSSDK(config('wechat.appid'), config('wechat.appsecret'));

            $erweima_text = request()->domain() . url('common/team_scan_code', ['parent_openid' => $member->openid,'parent_id' => $member->id]);

            $signPackage = $jssdk->getSignPackage();
            $view = new View();
            $view->assign('signPackage', $signPackage);
            $view->assign('erweima_text', $erweima_text);
            $view->assign('image', PUBLIC_URL . 'static/home/images/logo.png');
            $sdkjs = $view->fetch();
            return json(['code' => 200,'sdkjs' => $sdkjs]);
        }
        catch (\Exception $e)
        {
            return json(['code' => 0,'msg' => $e->getMessage()]);
        }
    }
}
